import datetime

from django.db.models.signals import post_init, post_save, post_delete
from django.dispatch import receiver

from building.models import Project, Archive


# 保存
@receiver(post_save, sender=Project)
def project_save_action(sender, instance, created, **kwargs):
    """创建更新档案表信息"""
    project_id = instance.id
    default = {
        "project_name": instance.name,
        "archive_date": instance.add_time.date(),
        "category_id": instance.category_id,
        "costs": instance.costs,
    }
    Archive.objects.update_or_create(project_id=project_id, defaults=default)

